import formatColumn from 'packages/BaseTableCell/formatColumn';
import i18n from '@src/locales';

// 高级搜索字段
export const getSearchFields = () => {
  return [
    {
      id: 5460,
      tableName: 'productWarranty',
      isSystem: 1,
      fieldName: 'product',
      displayName: i18n.t('common.base.product'),
      formType: 'text',
      defaultValue: null,
      isNull: 1,
      isSearch: 1,
      placeHolder: null,
      setting: {},
      orderId: 1,
      isDelete: 0,
      guideProfessions: [],
      show: true,
      isGuideData: false,
      guideData: false,
    },
    {
      id: 5460,
      tableName: 'productWarranty',
      isSystem: 1,
      fieldName: 'svcProjectName',
      displayName: i18n.t('common.product.serviceItemName'),
      formType: 'svcProjectName',
      defaultValue: null,
      isNull: 1,
      isSearch: 1,
      placeHolder: null,
      setting: {},
      orderId: 1,
      isDelete: 0,
      show: true,
      guideProfessions: [],
      isGuideData: false,
      guideData: false,
    },
    {
      id: 5460,
      tableName: 'productWarranty',
      isSystem: 1,
      fieldName: 'startTime',
      displayName: i18n.t('common.product.serviceStartTime'),
      formType: 'datetime',
      defaultValue: null,
      isNull: 1,
      isSearch: 1,
      placeHolder: null,
      setting: {},
      orderId: 1,
      isDelete: 0,
      guideProfessions: [],
      show: true,
      isGuideData: false,
      guideData: false,
    },
    {
      id: 5460,
      tableName: 'productWarranty',
      isSystem: 1,
      fieldName: 'endTime',
      displayName: i18n.t('common.product.serviceEndTime'),
      formType: 'datetime',
      defaultValue: null,
      isNull: 1,
      isSearch: 1,
      placeHolder: null,
      setting: {},
      orderId: 1,
      isDelete: 0,
      guideProfessions: [],
      show: true,
      isGuideData: false,
      guideData: false,
    },
  ]
}

// 服务项目表头
export const getServiceItemColumn = () => {
  return [
    {
      fieldName: 'svcSerialNumber',
      displayName: i18n.t('common.part.serviceProviderNo'),
      formType: 'text',
      isSearch: 0,
      isNull: 1,
      placeholder: ' ',
      disabled: true,
      tableName: 'productWarranty',
    },
    {
      fieldName: 'svcProjectName',
      displayName: i18n.t('common.product.serviceItemName'),
      formType: 'text',
      isSearch: 1,
      isNull: 0,
      placeholder: ' ',
      tableName: 'productWarranty',
    },
    {
      fieldName: 'serviceProjectCycle',
      displayName: i18n.t('common.product.serviceProjectCycle'),
      formType: 'number',
      isSearch: 1,
      isNull: 0,
      placeholder: ' ',
      setting: {
        decimalConfig: {
          digit: '0',
          isLimit: 1,
        },
        limitConig: {
          isLimit: 1,
          max: '',
          min: '0',
          type: 1,
        },
      },
      tableName: 'productWarranty',
    },
    {
      fieldName: 'svcRemark',
      displayName: i18n.t('common.product.serviceItemsDes'),
      formType: 'textarea',
      isSearch: 1,
      isNull: 1,
      placeholder: ' ',
      maxlength: 1000,
      tableName: 'productWarranty',
    },
  ].map(item => {
    // 初始化属性
    let field = {
      ...item,
      setting: item.setting || {},
      isSystem: 1,
      show: true,
      tableName: '',
    };
    return formatColumn(field);
  });
};

export const serviceTimeFields = [
  {
    fieldName: 'svcStartTime',
    displayName: i18n.t('common.product.serviceStartTime'),
    formType: 'date',
    isSearch: 0,
    isNull: 0,
    tableName: 'productWarranty',
  },
  {
    fieldName: 'svcEndTime',
    displayName: i18n.t('common.product.serviceEndTime'),
    formType: 'text',
    isSearch: 1,
    isNull: 1,
    disabled: true,
    placeholder: ' ',
    tableName: 'productWarranty',
  },
]
// 列表 && 选择列
export const getColumnFields = () => {
  let column = [...getServiceItemColumn(), ...serviceTimeFields];

  return column.map(item => {
    // 初始化属性
    let field = {
      ...item,
      setting: item.setting || {},
      isSystem: 1,
      show: true,
      tableName: '',
    };
    return formatColumn(field);
  });
};

// 子列表
export const subFields = () => {
  return [
    {
      fieldName: 'svcSerialNumber',
      displayName: i18n.t('common.part.serviceProviderNo'),
      formType: 'text',
      isSearch: 0,
      isNull: 0,
      placeholder: ' ',
    },
    {
      fieldName: 'svcProjectName',
      displayName: i18n.t('common.product.serviceItemName'),
      formType: 'text',
      isSearch: 1,
      isNull: 0,
      placeholder: ' ',
    },
  ];
};

export const periodOption = [
  {
    value: 'year',
    label: i18n.t('common.base.year'),
  },
  {
    value: 'month',
    label: i18n.t('common.base.month'),
  },
  {
    value: 'day',
    label: i18n.t('common.base.day2'),
  },
];
